package com.lyj.util;

import com.github.pagehelper.PageInfo;

import java.util.HashMap;
import java.util.Map;

public class LayuiData {
    public static Map<String, Object> toLayuiTableModel(PageInfo pageInfo) {
        Map<String, Object> layuiModel = new HashMap<>(4);
        layuiModel.put("code", 0);
        layuiModel.put("msg", "");
        layuiModel.put("count", pageInfo.getTotal());
        layuiModel.put("data", pageInfo.getList());
        return layuiModel;
    }

    public static Map<String, Object> toLayuiUploadError(int code,String msg) {
        Map<String, Object> layuiModel = new HashMap<>(2);
        layuiModel.put("code", code);
        layuiModel.put("msg", msg);
        return layuiModel;
    }
    public static Map<String, Object> toLayuiUploadSuccess(String url,String fileName) {
        Map<String, Object> layuiModel = new HashMap<>(3);
        layuiModel.put("code", 200);
        layuiModel.put("msg", "文件上传成功");
        Map<String, Object> data = new HashMap<>(2);
        data.put("src",url);
        data.put("fileName",fileName);
        layuiModel.put("data",data);
        return layuiModel;
    }

    public static Map<String, Object> success() {
        Map<String, Object> layuiModel = new HashMap<>(2);
        layuiModel.put("code", 200);
        layuiModel.put("msg", "");
        return layuiModel;
    }
    public static Map<String, Object> success(Object obj) {
        Map<String, Object> layuiModel = new HashMap<>(3);
        layuiModel.put("code", 200);
        layuiModel.put("msg", "");
        layuiModel.put("data", obj);
        return layuiModel;
    }

    public static Map<String, Object> error(int code,String msg) {
        Map<String, Object> layuiModel = new HashMap<>(2);
        layuiModel.put("code", code);
        layuiModel.put("msg", msg);
        return layuiModel;
    }
}
